<?php




	/*
	 * All rights Reserved, Designed By www.youyacao.com <br>
	 * @Description:订单 <br>
	 * @version 蜻蜓C影视追剧系统  <br>
	 * @author:成都市一颗优雅草科技有限公司  <br>
	 * 注意：使用我司开源源代码请遵循license文件的协议仅供个人非盈利使用，禁止用于其他的商业用途
	 * 需要商业用途或者定制开发等可访问songshu.youyacao.com  联系QQ:2853810243 422108995 23625059584
	 * 正版系统查询系统 zhengbancha.youyacao.com
	 */
namespace App\Admin\Controllers;

use App\Admin\Repositories\Order;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class OrderController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Order(['user', 'shop']), function (Grid $grid) {
            $grid->model()->orderByDesc('created_at');
            $grid->quickSearch(['user.phone', 'user.nickname', 'orderid', 'shop.name', 'shop.id'])->placeholder('可搜索手机号,用户昵称,商品id，商品名称')->width(30);
            $grid->column('id')->sortable();
            $grid->column('user.phone', '手机号');
            $grid->column('user.nickname', '用户');
            $grid->column('orderid');
            $grid->column('shop.name', '商品名');
            $grid->column('shop.price', '商品价格');
            $grid->column('shop.integral', '到账爽豆');
            $grid->column('type')->display(function ($type) {
                return \App\Models\Order::TYPE[$type];
            });
            $grid->column('status')->using([0 => '支付中', 1 => '支付成功', 2 => '已处理',])
                ->dot(
                    [
                        0 => 'primary',
                        1 => 'success',
                        2 => 'danger',
                        3 => Admin::color()->info(),
                    ],
                    'success' // 第二个参数为默认值
                );
            $grid->column('access_status')->using([0 => '未到账', 1 => '已到账', 2 => '已处理',])
                ->dot(
                    [
                        0 => 'primary',
                        1 => 'success',
                        2 => 'danger',
                        3 => Admin::color()->info(),
                    ],
                    'success' // 第二个参数为默认值
                );
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->disableCreateButton();
            // 禁用详情按钮
            $grid->disableViewButton();
            $grid->disableDeleteButton();
            $grid->disableEditButton();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Order(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('orderid');
            $show->field('shop_id');
            $show->field('type');
            $show->field('status');
            $show->field('access_status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Order(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('orderid');
            $form->text('shop_id');
            $form->text('type');
            $form->text('status');
            $form->text('access_status');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
